// store/index.js
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
let storePlayList = [];
try {
	const vaule = uni.getStorageSync("playList");
	if (value) {
		storePlayList = JSON.parse(value);
	}
} catch (e) {}
export default new Vuex.Store({
	state: {

		loggedInUser: null, 
		// 用于存储登录用户的账号
		playList: storePlayList,
	},
	
	mutations: {
		setLoggedInUser(state, user) {
			state.loggedInUser = user;
		},
		logout(state) {
			state.loggedInUser = null;
		},
	},
	actions: {
		login({
			commit
		}, user) {
			commit('setLoggedInUser', user);
		},
		logout({
			commit
		}) {
			commit('logout');
		},
		//保存播放列表
		storePlayList(state, payload) {
			state.playList = payload;
			
			//持久化存储
			uni.setStorageSync("playList", JSON.stringify(payload));
		}
	},
	
	getters: {
		loggedInUser: state => state.loggedInUser,
	},
	

})

